import time
import 小车.舵机.serial as serial

def main():
    ser=serial.Serial(port="/dev/ttyAMA0", baudrate=9600,timeout=5)
    if not ser.isOpen():
        ser.open()
    ser.write("/dev/ttyAMA0 is open,".encode("UTF-8"))

    try:
        while True:
            size=ser.inWaiting()
            if size==0:
                continue
            receive=ser.readline()
            print(receive,time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
            result='R='+receive
            ser.write(result.encode("UTF-8"))
            ser.flushInput()
            time.sleep(0.02)
    except Exception or KeyboardInterrupt as e:
        print('error',e)
        ser.close()

main()